<!DOCTYPE html>
<html class="x-admin-sm">
{include file='public/header'}
<style>
</style>
<body>
    <div class="x-body">
        <form class="layui-form" lay-filter="formAjax">
            <div class="layui-form-item">
                <label class="layui-form-label">提交类型：</label>
                <div class="layui-input-block">
                    <input type="radio" name="submit_type" lay-filter="submit_type" value="one" title="单个" checked>
                    <input type="radio" name="submit_type" lay-filter="submit_type" value="batch" title="批量">
                </div>
            </div>
            <div class="layui-form-item" style='display: flex;'>
                <label class="layui-form-label">
                    <span class="x-red">*</span>选择小程序
                </label>
                <div id="GetAuthorizers" style="width: 100%;flex: 1;"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">操作类型：</label>
                <div class="layui-input-block">
                    <input type="radio" name="privacy_ver" lay-filter="privacy_ver" value="1" title="现网版本" checked>
                    <input type="radio" name="privacy_ver" lay-filter="privacy_ver" value="2" title="开发版">
                </div>
            </div>
            <div class="layui-form-item" id="setting_list" style="display: none;">
                <label class="layui-form-label">用户信息配置：</label>
                <div class="layui-input-block" style="margin-bottom: 10px;" id="set_list">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="UserInfo" title="用户信息">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="Location" title="位置信息">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="Address" title="地址">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="Invoice" value="Address" title="发票信息">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="RunData" title="微信运动数据">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="Record" title="麦克风">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="Album" title="选中的照片或视频信息">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="Camera" title="摄像头">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="PhoneNumber" title="手机号码">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="Contact" title="通讯录（仅写入）权限">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="DeviceInfo" title="设备信息">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="EXIDNumber" title="身份证号码">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="EXOrderInfo" title="订单信息">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="EXUserPublishContent" title="发布内容">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="EXUserFollowAcct" title="所关注账号">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="EXUserOpLog" title="操作日志">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="AlbumWriteOnly" title="相册（仅写入）权限">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="LicensePlate" title="车牌号">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="BlueTooth" title="蓝牙">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="CalendarWriteOnly" title="日历（仅写入）权限">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="Email" title="邮箱">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="MessageFile" title="选中的文件">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="ChooseLocation" title="选择的位置信息">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="Accelerometer" title="加速传感器">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="Compass" title="磁场传感器">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="DeviceMotion" title="方向传感器">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="Gyroscope" title="陀螺仪传感器">
                    <input type="checkbox" name="privacy_key" lay-skin="primary" lay-filter="setting_list" value="Clipboard" title="剪切板">
                </div>
                <div class="layui-input-block" id="set_list_arr">
                    
                </div>
            </div>
            <fieldset class="layui-elem-field">
                <legend>开发者信息配置</legend>
                <div class="layui-field-box owner">
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            手机号
                        </label>
                        <div class="layui-input-block">
                            <input type="text" data-name="contact_phone" placeholder="请填写信息收集方（开发者）的手机号" autocomplete="off" class="layui-input" value="" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            邮箱地址
                        </label>
                        <div class="layui-input-block">
                            <input type="text" data-name="contact_email" placeholder="请填写信息收集方（开发者）的邮箱地址" autocomplete="off" class="layui-input" value="" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            qq号
                        </label>
                        <div class="layui-input-block">
                            <input type="text" data-name="contact_qq" placeholder="请填写信息收集方（开发者）的qq号" autocomplete="off" class="layui-input" value="" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            微信号
                        </label>
                        <div class="layui-input-block">
                            <input type="text" data-name="contact_weixin" placeholder="请填写信息收集方（开发者）的微信号" autocomplete="off" class="layui-input" value="" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            存储期限<i class="layui-icon iconfont icon-lytishi1" id="store_expire_timestamp"></i>
                        </label>
                        <div class="layui-input-block">
                            <input type="number" data-name="store_expire_timestamp" placeholder="请填写存储期限" autocomplete="off" class="layui-input" value="" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="x-red">*</span>通知方式<i class="layui-icon iconfont icon-lytishi1" id="notice_method"></i>
                        </label>
                        <div class="layui-input-block">
                            <input type="text" data-name="notice_method" placeholder="请填写存储期限" autocomplete="off" required="required"
                            lay-verify="required" class="layui-input owner" value="" />
                        </div>
                    </div>
                </div>
            </fieldset>
            
            <button id="submitData" class="layui-btn" lay-submit lay-filter="submitData" style="display: none;" />
        </form>
    </div>
    <script>
        var setting_list = [];
        var owner_setting = {};
        layui.use(["form", "layer"], function () {
            var form = layui.form,
                layer = layui.layer;

            form.on('radio(privacy_ver)', function(data){
                $("#setting_list").css('display',data.value == 1 ? 'none' : 'block')
            });

            form.on('checkbox(setting_list)', function(data){
                let titles = $(this).attr('title');
                let set_list_arr = ``;
                if(data.elem.checked){
                    set_list_arr += `
                    <div class="layui-form-item" item-name='${data.value}'>
                        <label class="layui-form-label" style="width: 80px;">
                            <span class="x-red">*</span>${titles}
                        </label>
                        <div class="layui-input-block" style="margin-left: 110px;">
                            <input type="text" name="${data.value}" placeholder="请填写${titles}" autocomplete="off" required="required" lay-verify="required" class="layui-input" value="" />
                        </div>
                    </div>
                    `
                }else{
                    $("#set_list_arr").children().each((index,item)=>{
                        if($(item).attr('item-name') == data.value){
                            $(item).remove()
                        }
                    })
                }
                $("#set_list_arr").append(set_list_arr)
            });

            form.on('submit(submitData)', function(data){
                var formData = data.field;
                let url = '/admin/OpenWeixin/postSetPrivacySetting';
                if(formData["owner_setting[contact_phone]"] == '' && formData["owner_setting[contact_qq]"] == '' && formData["owner_setting[contact_weixin]"] == '' && formData["owner_setting[contact_email]"] == '' ){
                    layer.msg('4种联系方式至少要填一种',{icon:5,time:1500});
                    return false;
                }else{
                    formData.setting_list = setting_list;
                    formData.owner_setting = owner_setting;
                    if(form.val("formAjax").submit_type == 'one'){
                        formReloadAjax(url,formData)
                    }else{
                        batchTask({
                            app_ids:form.val("formAjax").app_id.split(','),
                            task_method:'postSetPrivacySetting',
                            task_data:formData
                        })
                    }
                    return false
                }
                return false
            });
            form.on('radio(submit_type)', function(data){
                let app_id = form.val("formAjax").app_id.split(',');
                if(data.value == 'one'){
                    xmSelectGetAuthorizersOption.initValue = app_id.length == 0 ? '' : [app_id[0]]
                    xmSelectGetAuthorizersOption.radio = true;
                    xmSelectGetAuthorizersOption.clickClose = true;
                    xmSelectGetAuthorizersOption.label = {
                        type:'text'
                    };
                }else{
                    xmSelectGetAuthorizersOption.initValue = app_id ?? ''
                    xmSelectGetAuthorizersOption.radio = false;
                    xmSelectGetAuthorizersOption.clickClose = false;
                    xmSelectGetAuthorizersOption.label = {
                        type:'block'
                    };
                }
                xmSelectA(xmSelectGetAuthorizersOption)
            });
        });

        let xmSelectGetAuthorizersOption = {
            initValue:'',//初始值
            el:'#GetAuthorizers',
            url:'/admin/OpenWeixin/getAuthorizersSelect',
            direction:'down',//下拉方向
            isData:true,
            prop:{
                name:'app_name',
                value:"app_id"
            },
            radio:true,
            clickClose:true,
            label: {
                type: 'text'
            },
            pageSize:8,
            name:'app_id',
        }
        xmSelectA(xmSelectGetAuthorizersOption)

        tips('#store_expire_timestamp', '#store_expire_timestamp', '如果不填则展示为【开发者承诺，除法律法规另有规定，开发者对你的信息保存期限应当为实现处理目的所必要的最短时间】，如果填请填数字+天，例如“30天”，否则会出现87072的报错。')
        tips('#notice_method', '#notice_method', '通知方式，指的是当开发者收集信息有变动时，通过该方式通知用户。这里服务商需要按照实际情况填写，例如通过弹窗或者公告或者其他方式。')

        // 用户信息配置
        $('#set_list_arr').on('input', 'input', function() { 
            let names = $(this).attr('name');
            let val = $(this).val();
            // 遍历数组
            for (let i = 0; i < setting_list.length; i++) {
                // 检查对象是否具有给定的名称
                if (setting_list[i].privacy_key === names) {
                    // 更新对象的值
                    setting_list[i].privacy_text = val;
                    return setting_list;
                }
            }
            // 如果不存在具有相同名称的对象，则添加新对象
            setting_list.push({ privacy_key: names, privacy_text: val });
        })
        // 开发者信息配置
        $('.owner').on('input', 'input', function() { 
            let names = $(this).data('name');
            let val = $(this).val();
            owner_setting[names] = val;
        })
    </script>
</body>

</html>